﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UIDesigner.FieldHandlers;
using DDW;
using DDW.Collections;

namespace UIDesigner.ObjectHandlers
{
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
    public class ObjectHandlerAttribute : System.Attribute
    {
        private float m_fPriorityNumber;
        private Type m_objMetadataAttributeType;

        public float PriorityNumber
        {
            get 
            {
                return m_fPriorityNumber; 
            }
        }

        public Type MetadataAttributeType
        {
            get 
            { 
                return m_objMetadataAttributeType; 
            }
        }

        public ObjectHandlerAttribute(float fPriorityNumber, Type objMetadataAttributeType)
        {
            m_fPriorityNumber = fPriorityNumber;
            m_objMetadataAttributeType = objMetadataAttributeType;
        }

        public ObjectHandlerAttribute(int fPriorityNumber)
        {
            m_fPriorityNumber = fPriorityNumber;
            m_objMetadataAttributeType = null;
        }
    }

    public abstract class BaseObjectHandler : IObjectHandler
    {
        public abstract bool Handles(IType objType, NodeCollection<AttributeNode> rgAttributes);
        public abstract List<string> ControlOptions { get; }
        public abstract void AddDefaultControls(System.Windows.Forms.Control ctrlParent);
        public abstract void AddControls(string strOption, System.Windows.Forms.Control ctrlParent);
        public abstract void AddDemoDefaultControls(System.Windows.Forms.Control ctrlParent);
        public abstract void AddDemoControls(string strOption, System.Windows.Forms.Control ctrlParent);

        public static SortedDictionary<float, IObjectHandler> FindHandlers(TypeNode objType)
        {
            SortedDictionary<float, IObjectHandler> rgHandlers = new SortedDictionary<float, IObjectHandler>();

            return rgHandlers;
        }

        public float PriorityNumber
        {
            get
            {
                return -1;
            }
        }

        public Type MetadataAttributeType
        {
            get
            {
                return this.GetType();
            }
        }
    }
}
